﻿using System;
using System.Collections.Generic;

namespace EasySL.Core
{
    public class TaskManager
    {
        public event EventHandler<EventArgs> OnCompleted;

        public List<Task> TaskProcs
        {
            get
            {
                return this._taskProcs;
            }
        }

        public bool HasNext
        {
            get
            {
                return (this._taskProcs.Count > 0 &&
                        this._curTaskIndex < this._taskProcs.Count - 1);
            }
        }

        public Dictionary<string, string> Settings
        {
            get
            {
                return this._settings;
            }
        }


        public void Next()
        {
            if (this.HasNext)
            {
                this._curTaskIndex++;
                Task proc = this._taskProcs[this._curTaskIndex];
                proc.Start(this, null);
            }
            else
            {
                if (this.OnCompleted != null)
                {
                    this.OnCompleted(this, null);
                }
            }
        }

        public void Start()
        {
            this._curTaskIndex = -1;

            this.Next();
        }

        public void Clear()
        {
            this._settings.Clear();
            this._taskProcs.Clear();
            this._curTaskIndex = -1;
        }


        private List<Task> _taskProcs = new List<Task>();
        private int _curTaskIndex = -1;

        private Dictionary<string, string> _settings = new Dictionary<string, string>();
    }
}
